	<?php

	require_once($_SERVER['DOCUMENT_ROOT'].'/conciergerie/espace_administration/Controller/ListeServiceController.php');		
	require_once($_SERVER['DOCUMENT_ROOT'].'/conciergerie/espace_administration/Controller/FamilleController.php');		
	require_once($_SERVER['DOCUMENT_ROOT'].'/conciergerie/espace_administration/Controller/PrestationController.php');
	require_once($_SERVER['DOCUMENT_ROOT'].'/conciergerie/espace_client/Controller/CommandeServiceController.php');
	require_once($_SERVER['DOCUMENT_ROOT'].'/restricted/Model/ListeServiceBDD.php');
	require_once($_SERVER['DOCUMENT_ROOT'].'/restricted/Model/UtilisateurBDD.php');
	$serviceController = new ListeServiceController();
	$db_service = new ListeServiceBDD();
	$db_users = new UtilisateurBDD();
	$familleController = new FamilleController();
    $prestationController = new PrestationController();	
	
	if ( isset($_GET['action']) AND $_GET['action']=='creation' )
	{	
		if ( isset($_POST['nbChamps']) && $_POST['nbChamps'] > 0 )	
		{		
		$j=0;
		$vardump='';
		$commande = array();
		$nbChamps = $_POST['nbChamps'];
		for ( $i=0 ; $i< $nbChamps; ){
			$ligne = array();
			$ligne['code_service'] = $_POST[$i++];
			$ligne['quantite'] = $_POST[$i++];
			$ligne['com_client'] = $_POST[$i++];
			
			$service_info = $db_service->fetchService($ligne['code_service']);
			$ligne['libelle_service'] = $service_info[0]['libelle_service'];
			$ligne['prix_unitaire_HT'] = $service_info[0]['prix_unitaire_HT'];
			$ligne['taux_tva'] = $service_info[0]['taux_tva'];
			$ligne['commentaire'] = $service_info[0]['commentaire'];
			
			$commande[$j++]= $ligne;
		}
		
		$userInfo = $db_users->fetchUser($_SESSION['user']);
		
		include('demande_service/validation.php');
		 
//		$db_service->addLigneCommande( 		
//			$_POST['code_service_commande'], 
//			$_POST['code_commande'], 
//			$_POST['enseigne_fournisseur'], 
//			$_POST['quantite'], 
//			$_POST['cout_total_ht'], 
//			$_POST['cout_total_ttc'], 
//			$_POST['commentaire']);	
		}
	}
	else if ( isset($_GET['action']) AND $_GET['action']=='validation'  )	{
		
		
	}else{
			
	//$userInfo = "Test" ; //$userController->getUserInfo($_SESSION['user']);
	$listeService = $serviceController->fetchAllService();
	$listeFamille = $familleController->fetchAllFamille();
	$listePrestation = $prestationController->fetchAllPrestation();
	
  	include($_SERVER['DOCUMENT_ROOT']."/conciergerie/espace_client/demande_service/creation_commande.php");
	}